//---------------------------------------------------------------------------
#include "MyUtility.h"
#ifndef MY_STREAM
#define MY_STREAM
//---------------------------------------------------------------------------
#define STREAM_CORRECT          0xC00
#define STREAM_INVALID_ALLOCATE 0xC01
#define STREAM_INVALID_FILE     0xC02
#define STREAM_ERR_SEEK_FILE    0xC03
#define STREAM_ERR_FTELL_FILE   0xC04
#define STREAM_WRONG_BYTES_READ 0xC05
#define STREAM_WRONG_CLOSE      0xC06
#define STREAM_WRONG_BYTES_WRT  0xC07
//---------------------------------------------------------------------------
#define BUFFER_LOAD_SOURCE      0xE0
#define FILE_LOAD_SOURCE        0xE1
//---------------------------------------------------------------------------
typedef struct{
    DWORD Source;
    DWORD Result;
    DWORD LoadSize;
    void *SourceData;
    DWORD AddInfo;
}StreamLoadInfo;
//---------------------------------------------------------------------------
#ifdef MY_BORLAND
class PACKAGE MyStream{
#else
class MyStream{
#endif
    public:
        MyStream(void);
        ~MyStream(void);
        DWORD Clear(void);
        //Loading function
        DWORD LoadFromBuffer(void *Buffer, int BufferSize);
        DWORD LoadFromFile(char *FileName); 
        //Saving function       
        DWORD SaveToBuffer(void *Buffer);
        DWORD SaveToFile(char *FileName);
        //Inserting function
        DWORD InsertFromBuffer(void *Src, int SrcLen,int Pos);
        DWORD WriteFromBuffer(void *Src, int SrcLen, int Pos);
#ifndef MY_BORLAND
        void *GetData();
        int GetSize();
        void SetSize(int NewSize);
        virtual void OnLoadData(DWORD InfoSource);
        virtual void OnSaveData(DWORD InfoSource);
#else
        __property unsigned char *Data = {read = GetData};
        __property int Size = {read = GetSize, write = SetSize};
        void (__closure *OnLoadData)(DWORD InfoSource);
        void (__closure *OnSaveData)(DWORD InfoSource);        
#endif        
    private:
        
    protected:
        int FSize;  
        unsigned char *FData;  
        
        void DummyLoadData(DWORD InfoSource);        
        void DummySaveData(DWORD InfoSource);          
#ifndef MY_BORLAND

#else
        void *GetData();
        int GetSize();
        void SetSize(int NewSize);        
#endif        
};
//---------------------------------------------------------------------------
#endif
